<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <form id="myform" method="post" enctype="multipart/form-data"> 
        <input type="file" name="file" >
        <button>提交</button>
    </form>
</body>
<script>
    let myform= document.getElementById("myform");
    myform.addEventListener("click",e=>{
        e.preventDefault();
        let xhr = new XMLHttpRequest();
        xhr.open("localhost:3000/upload");
        xhr.onload = function(){
          console.log("已完成")
        }
        xhr.upload = function(event){
            if(event.lengthComputable){
                var percent = event.loaded /event.total;
                console.log(percent);
            }
        }
        xhr.end();
    }
    )

</script>
</html>